<template>
  <div class="searchStation">
    <div class="search_view">
      <img :src="search_icon" alt class="search_icon" @click="getSelectList()">
      <input type="text" name id class="input" placeholder="搜寻站点" @blur="inputBack()">
    </div>
    <div class="list_view" ref="warpper1">
      <div>
        <div class="all" @click="select({})">全部</div>
        <div class="list" v-for="(item,index) in selectList" :key="index">
          <div class="station_view" @click="select(item)">
            <i class="iconfont icon-dizhi address_icon"></i>
            <span>{{item.title}}</span>
          </div>
          <div class="address">{{item.address}}</div>
        </div>
      </div>
    </div>
  </div>
</template>
   
<style lang="less" scoped>
@import "index.less";
</style>

<script>
import BScroll from "better-scroll";
import {mapActions} from "vuex";
export default {
  name: "searchStation",
  data() {
    return {
      search_icon: require("../../../assets/images/search_icon.png"),
      // 请求参数

      selectPage: 1,
      title: "",
      // 后台

      selectList: {},
      scroll: {},
      lock: false
    };
  },
  created() {
    this.getSelectList();
  },
  methods: {
    ...mapActions('Select',['setInSelect']),
    selectScrollInit() {
      this.scroll = new BScroll(this.$refs.warpper1, {
        click: true,
        pullUpLoad: {
          threshold: -50
        }
      });
      this.scroll.on("pullingUp", () => {
        if (this.lock) {
          return;
        }
        // 页数加一
        this.selectPage++;
        // 锁定防止多次加载
        this.lock = true;
        this.$dialog.loading.open("正在加载");
        this.$http
          .get(
            "/device/Adminlist",
            {
              params: {
                page: this.selectPage
              }
            }
          )
          .then(res => {
            this.lock = false;
            this.selectList = this.selectList.concat(res.data.data);
            this.$forceUpdate();
            this.scroll.finishPullUp();
            this.scroll.refresh();
            this.$dialog.loading.close();
          });
      });
    },
    getSelectList() {
      this.selectPage = 1;
      this.$dialog.loading.open("正在加载");
      this.$http
        .get(
          "/device/Adminlist",
          {
            params: {
              page: this.selectPage
            }
          }
        )
        .then(res => {
          this.selectList = res.data.data;
          this.selectScrollInit();
          this.$dialog.loading.close();
        });
    },
    select(item) {
      console.log(item);
      this.setInSelect(item)
      this.$router.push({
        path:"/Count"
      })
    }
  },
  computed:{
    
  },
  components: {}
};
</script>
